package com.fortune.service.impl;

import com.fortune.constants.RoleConstants;
import com.fortune.dao.FindFhoneIsExistDao;
import com.fortune.dto.in.distributorMgt.DAccountEditDto;
import com.fortune.service.FindFhoneIsExistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class FindFhoneIsExistServiceImpl implements FindFhoneIsExistService {
    @Autowired
    private FindFhoneIsExistDao findFhoneIsExistDao;

    /**
     * 查看手机号全网是否存在
     * @param phone
     * @return
     */
    @Override
    public int findFhoneIsExist(String phone) {
        int num = findFhoneIsExistDao.findMuserFhoneIsExist(phone);
        if (num > 0){
            return num;
        }
        num = findFhoneIsExistDao.findDuserFhoneIsExist(phone);
        if (num > 0){
            return num;
        }
        num = findFhoneIsExistDao.findPuserFhoneIsExist(phone);
        if (num > 0){
            return num;
        }
        return 0;
    }

    /**
     * 查看手机号全网是否存在--编辑厂商--平台
     * @param phone
     * @param id
     * @return
     */
    @Override
    public int findAddMFhoneIsExist(String phone, String id) {
        String adminId = RoleConstants.SUPER_ADMIN_ID;
        int num = findFhoneIsExistDao.findMuserFhoneIsExistEdit(phone,id,adminId);
        if (num > 0){
            return num;
        }
        num = findFhoneIsExistDao.findDuserFhoneIsExist(phone);
        if (num > 0){
            return num;
        }
        num = findFhoneIsExistDao.findPuserFhoneIsExist(phone);
        if (num > 0){
            return num;
        }
        return 0;
    }

    /**
     * 查看手机号全网是否存在--编辑经销商--平台
     * @param dAccountEditDto
     * @return
     */
    @Override
    public int findDFhoneIsExistEdit(DAccountEditDto dAccountEditDto) {
        String phone = dAccountEditDto.getPrincipalPhone();
        String adminId = RoleConstants.SUPER_ADMIN_ID;
        int num = findFhoneIsExistDao.findDuserFhoneIsExistEdit(phone,dAccountEditDto.getId(),adminId);
        if (num > 0){
            return num;
        }
        num = findFhoneIsExistDao.findMuserFhoneIsExist(phone);
        if (num > 0){
            return num;
        }
        num = findFhoneIsExistDao.findPuserFhoneIsExist(phone);
        if (num > 0){
            return num;
        }
        return 0;
    }


}
